home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / mac / Chapter Tutorials / CaseStudies / ch11.earshotSFX / earMenu.dir / 00001_non-sequential load queue scripts.ls next >
Encoding:
Text File  |  1996-11-12  |  5.5 KB  |  198 lines

  1. on startMovie
  2.   global gReadyToGo, gMovieStartTime
  3.   set gReadyToGo to 0
  4.   set gMovieStartTime to the ticks
  5.   initPreloadStuff()
  6.   netAbort()
  7.   localInit()
  8.   pass()
  9. end
  10.  
  11. on initPreloadStuff
  12.   global gBaseURL, gMaxWaitTime, gMaxRetries, gPreloadList, gLoadStatus, gCurrLoading, gPreloadingOn, gRetries
  13.   set gMaxWaitTime to 22 * 60
  14.   set gMaxRetries to 3
  15.   if not gRetries then
  16.     set gRetries to 0
  17.   end if
  18.   if not gPreloadList then
  19.     set gPreloadList to []
  20.   end if
  21.   if not gLoadStatus then
  22.     set gLoadStatus to []
  23.   end if
  24.   if not gCurrLoading then
  25.     set gCurrLoading to EMPTY
  26.   end if
  27.   set gPreloadingOn to 0
  28. end
  29.  
  30. on addToLoadQueue theFile
  31.   global gPreloadList, gLoadStatus
  32.   if gLoadStatus <> "[]" then
  33.     repeat with i = 1 to count(gLoadStatus)
  34.       if getPos(getAt(gLoadStatus, i), theFile) = 1 then
  35.         exit
  36.       end if
  37.     end repeat
  38.   end if
  39.   set PropTemplate to [#name: theFile, #ID: 0, #loaded: 0, #error: EMPTY]
  40.   append(gPreloadList, theFile)
  41.   append(gLoadStatus, PropTemplate)
  42. end
  43.  
  44. on checkQueue
  45.   global gCurrLoading, gLoadStatus, gBaseURL, gRetries, gMaxRetries
  46.   if gLoadStatus <> [] then
  47.     if gCurrLoading = EMPTY then
  48.       set gCurrLoading to 0
  49.     end if
  50.     if not (gCurrLoading > count(gLoadStatus)) and (gCurrLoading <> 0) then
  51.       set currLoaded to getaProp(getAt(gLoadStatus, gCurrLoading), #loaded)
  52.       if (currLoaded = 1) and (count(gLoadStatus) > gCurrLoading) then
  53.         set gCurrLoading to gCurrLoading + 1
  54.         put "checkQueue:wake up"
  55.         set currID to getLoadID(getaProp(getAt(gLoadStatus, gCurrLoading), #name))
  56.         setaProp(getAt(gLoadStatus, gCurrLoading), #ID, currID)
  57.       end if
  58.       set currID to getaProp(getAt(gLoadStatus, gCurrLoading), #ID)
  59.       if (netDone(currID) = 1) and (getaProp(getAt(gLoadStatus, gCurrLoading), #loaded) = 0) then
  60.         if netError(currID) = "OK" then
  61.           if not (NetTextResult(gCurrID) contains "not found") then
  62.             put "checkQueue:recv OK, updating"
  63.             setaProp(getAt(gLoadStatus, gCurrLoading), #loaded, 1)
  64.           else
  65.             setaProp(getAt(gLoadStatus, gCurrLoading), #loaded, 0)
  66.             setaProp(getAt(gLoadStatus, gCurrLoading), #error, "not found")
  67.           end if
  68.           if count(gLoadStatus) > gCurrLoading then
  69.             put "checkQueue:get new"
  70.             set gCurrLoading to gCurrLoading + 1
  71.             set currID to getLoadID(getaProp(getAt(gLoadStatus, gCurrLoading), #name))
  72.             setaProp(getAt(gLoadStatus, gCurrLoading), #ID, currID)
  73.             set gRetries to 0
  74.           end if
  75.         else
  76.           if netError(currID) = EMPTY then
  77.             nothing()
  78.           else
  79.             if netError(currID) contains "error" then
  80.               put "checkQueue:transfer error"
  81.               if gRetries > gMaxRetries then
  82.                 if count(gLoadStatus) > gCurrLoading then
  83.                   set gCurrLoading to gCurrLoading + 1
  84.                 else
  85.                   set gRetries to gRetries + 1
  86.                   exit
  87.                 end if
  88.               end if
  89.               set currID to getLoadID(getaProp(getAt(gLoadStatus, gCurrLoading), #name))
  90.               setaProp(getAt(gLoadStatus, gCurrLoading), #ID, currID)
  91.             end if
  92.           end if
  93.         end if
  94.       end if
  95.     else
  96.       set gCurrLoading to gCurrLoading + 1
  97.       put "checkQueue:starting up"
  98.       set currID to getLoadID(getaProp(getAt(gLoadStatus, gCurrLoading), #name))
  99.       setaProp(getAt(gLoadStatus, gCurrLoading), #ID, currID)
  100.     end if
  101.   else
  102.     if gCurrLoading <> EMPTY then
  103.       set gCurrLoading to EMPTY
  104.     end if
  105.   end if
  106. end
  107.  
  108. on getLoadID theFile
  109.   PreloadNetThing(theFile)
  110.   set currID to GetLatestNetID()
  111.   return currID
  112. end
  113.  
  114. on clearPreloadList
  115.   global gLoadStatus, gCurrLoading
  116.   set gLoadStatus to []
  117.   set gCurrLoading to EMPTY
  118. end
  119.  
  120. on preloadRange start, stop
  121.   preLoadCast(start, stop)
  122.   put "loaded to " & the result
  123. end
  124.  
  125. on WaitForTicks theTicks
  126.   set startTime to the timer
  127.   repeat while (startTime + theTicks) > the timer
  128.     nothing()
  129.   end repeat
  130. end
  131.  
  132. on goMovie theMovie
  133.   global gPreloadingOn, gCurrLoading, gLoadStatus, gBaseURL, gReadyToGo
  134.   if not (theMovie contains ".dcr") then
  135.     set theMovie to theMovie & ".dcr"
  136.   end if
  137.   if not (theMovie contains getaProp(getAt(gLoadStatus, gCurrLoading), #name)) then
  138.     netAbort()
  139.   end if
  140.   set gPreloadingOn to 0
  141.   set fadeDuration to 200
  142.   if soundBusy(1) or soundBusy(2) then
  143.     set lPlaying to 1
  144.   end if
  145.   if soundBusy(1) then
  146.     sound fadeOut 1, fadeDuration
  147.   end if
  148.   if soundBusy(2) then
  149.     sound fadeOut 2, fadeDuration
  150.   end if
  151.   if lPlaying = 1 then
  152.     WaitForTicks(fadeDuration)
  153.   end if
  154.   set gReadyToGo to 1
  155.   goToNetMovie(theMovie)
  156. end
  157.  
  158. on goPage thePage
  159.   global gPreloadingOn, gCurrLoading, gLoadStatus, gReadyToGo, gBaseURL
  160.   if not (thePage contains getaProp(getAt(gLoadStatus, gCurrLoading), #name)) and not netDone() then
  161.     netAbort()
  162.   end if
  163.   set gPreloadingOn to 0
  164.   set gReadyToGo to 1
  165.   GoToNetPage(thePage)
  166.   set fadeDuration to 200
  167.   if soundBusy(1) or soundBusy(2) then
  168.     set lPlaying to 1
  169.   end if
  170.   if soundBusy(1) then
  171.     sound fadeOut 1, fadeDuration
  172.   end if
  173.   if soundBusy(2) then
  174.     sound fadeOut 2, fadeDuration
  175.   end if
  176.   if lPlaying = 1 then
  177.     WaitForTicks(fadeDuration)
  178.   end if
  179. end
  180.  
  181. on idle
  182.   global gPreloadingOn
  183.   if gPreloadingOn = 1 then
  184.     checkQueue()
  185.   end if
  186.   pass()
  187. end
  188.  
  189. on getFileName theURL
  190.   repeat with i = the number of chars in theURL down to 1
  191.     if (char i of theURL = "/") or (char i of theURL = ":") then
  192.       set rVal to char i + 1 to the number of chars in theURL of theURL
  193.       exit repeat
  194.     end if
  195.   end repeat
  196.   return rVal
  197. end
  198.